package org.misalen.web.admin.controllers;

import org.misalen.web.admin.util.ServerResult;
import org.misalen.web.database.model.mysql.pro.ProAdvertOrder;
import org.misalen.web.database.model.mysql.pro.ProOwnerUser;
import org.misalen.web.database.repository.mysql.ProAdvertOrderRepository;
import org.misalen.web.database.util.PaginationFrom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/pro-owner")
public class ProOwnerController extends BaseController {

	@Autowired
	protected ProAdvertOrderRepository proAdvertOrderRepository;

	/**
	 * 列表页
	 * 
	 * @return 列表目标页
	 */
	@RequestMapping(value = "/", method = { RequestMethod.GET })
	public ModelAndView list() {
		ModelAndView modelAndView = new ModelAndView("/proOwner/list");
		return modelAndView;
	}

	/**
	 * 列表
	 * 
	 * @param 搜索条件
	 * @param 分页/排序条件
	 * @return 查询结果
	 */
	@RequestMapping(value = "/", method = { RequestMethod.POST })
	public @ResponseBody ServerResult listPost(ProOwnerUser proOwnerUser, PaginationFrom<ProOwnerUser> pagination) {
		String belongCity = getShiroUser().getBelongCity();
		if(!belongCity.equals("全国")) {
			proOwnerUser.setBelongCity(belongCity);;
		}
		
		PaginationFrom<ProOwnerUser> from = proOwnerUserRepository.findPageByBean(proOwnerUser, pagination);
		return renderSuccess(from);
	}
	
	/**
	 * 列表页
	 * 
	 * @return 列表目标页
	 */
	@RequestMapping(value = "/order/", method = { RequestMethod.GET })
	public ModelAndView orderList() {
		ModelAndView modelAndView = new ModelAndView("/proOwner/order/list");
		return modelAndView;
	}

	/**
	 * 列表
	 * 
	 * @param 搜索条件
	 * @param 分页/排序条件
	 * @return 查询结果
	 */
	@RequestMapping(value = "/order/", method = { RequestMethod.POST })
	public @ResponseBody ServerResult orderListPost(ProAdvertOrder proAdvertOrder, PaginationFrom<ProAdvertOrder> pagination) {
		String belongCity = getShiroUser().getBelongCity();
		if(!belongCity.equals("全国")) {
			proAdvertOrder.setBelongCity(belongCity);;
		}
		
		PaginationFrom<ProAdvertOrder> from = proAdvertOrderRepository.findPageByBean(proAdvertOrder, pagination);
		return renderSuccess(from);
	}
}